﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Manage/TeacherMasterPage.master" AutoEventWireup="true" CodeFile="CourseList.aspx.cs" Inherits="Manage_Questions" %>
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">

<style>
.pmain{text-align:left;margin:2px;}
</style>
<script>
$(function() {
    $("#dg tbody tr").hoverIntent(
        function() { $(this).children().css("background-color", "#F2F4F6"); },
        function() { $(this).children().css("background-color", "#FFFFFF"); }
    );
    $('#BtnAdd').click(function(e) {
        $('#Add-modal-content').modal({
            opacity: 55, zIndex: 10,
            onOpen: function(dialog) {
                dialog.overlay.fadeIn('fast', function () {
                    dialog.data.hide();
                    dialog.container.fadeIn('fast', function() {
                        dialog.data.show(); //slideDown('slow');
                    });
                });
            }
        });
        return false;
    });
    $(".btn").mouseover(function () { $(this).css("color", "#FF0000"); }).mouseout(function () { $(this).css("color", "#555"); });
});
function addNew() {
    var cname = $("#coursename").val();
    if(cname==""){
        alert("<%= Resources.labels.CourseListAddCourse %>"); return false;
    }
    $.ajax({
        type: "POST",
        cache: false,
        url: "Service/addNewCourse.aspx",
        data: "cname=" + cname + "&cdesc=" + $("#coursedesc").val(),
        success: function(msg) {
            if (msg == "1") {
                alert("<%= Resources.labels.Add_ok %>");
                $.modal.close();
                window.location.href = location.href;
            } else {
                alert("<%= Resources.labels.Add_Fail %>");
            }
        },
        error: function(msg) {
            alert("<%= Resources.labels.Add_Err %>");
            //$.modal.close();
        }
    });
}
function editCourse(id){
    $('#DivEditContainer').modal({
        opacity: 55, zIndex: 10, minHeight:450,
        onOpen: function(dialog) {
            getCourseInfo(id);
            dialog.overlay.fadeIn('slow', function() {
                dialog.data.hide();
                dialog.container.fadeIn('fast', function() {
                    dialog.data.show(); //slideDown('slow');
                });
            });
        }
    });
}
function addNewKnow(cid) {
    var knowtxt = $("#NewKnowTxt").val();
    if (knowtxt == "") {
        return false;//此处可加提示
    }
    $("#addknowstatus").html("&nbsp;<img src='../images/loading16x16.gif' border=0 style='vertical-align:middle;' /><%= Resources.labels.PleaseWaiting%>").show();
    $.ajax({
        type: "POST",
        cache: false,
        url: "Service/addKnowledge.aspx",
        data: "kname=" + knowtxt + "&cid=" + cid,
        success: function (msg) {
            if (msg == "1") {
                $("#addknowstatus").html("&nbsp;<img src='../images/ok.png' border=0 style='vertical-align:middle;' /><%= Resources.labels.Add_ok %>").css("color", "#066606");
                window.setTimeout("getCourseInfo("+cid+")", 2000);

            } else {
                $("#addknowstatus").html("&nbsp;<img src='../images/erro.png' border=0 style='vertical-align:middle;' /><%= Resources.labels.Add_Fail%>").css("color", "#FF0000");

            }
        },
        error: function (msg) {
            $("#addknowstatus").html("&nbsp;<img src='../images/erro.png' border=0 style='vertical-align:middle;' /><%= Resources.labels.Add_Err%>").css("color", "#FF0000");
        }
    });
}
function _getCourseInfo(cid) {
    return function () { getCourseInfo(cid);}
}

function delCourse(id) {
    confirm("<%= Resources.labels.ConfirmDelete%>", function () {
        $.ajax({
            type: "POST",
            cache: false,
            url: "Service/delcourse.aspx",
            data: "id=" + id,
            beforeSend: function () {
                $(".status").html("&nbsp;<img src='../images/loading16x16.gif' border=0 style='vertical-align:middle;' /><%= Resources.labels.PleaseWaiting%>").show();
            },
            success: function (msg) {
                if (msg == "1") {
                    $("#statusDel").html("&nbsp;<img src='../images/ok.png' border=0 style='vertical-align:middle;' /><%= Resources.labels.Del_ok%>").css("color", "#066606");
                    window.setTimeout(refresh, 2000);
                    
                }
                else {
                    $("#statusDel").html("&nbsp;<img src='../images/erro.png' border=0 style='vertical-align:middle;' /><%= Resources.labels.Del_Fail%>").css("color", "#FF0000");
                }
            },
            error: function (msg) {
                $("#statusDel").html("&nbsp;<img src='../images/erro.png' border=0 style='vertical-align:middle;' /><%= Resources.labels.Del_Fail%>").css("color", "#FF0000");
            }
        });
    });
}
function refresh() {
    window.location.href = window.location.href;
}

function confirm(message, callback) {
    $('#confirm').modal({
        closeHTML: "<a href='#' title='Close' class='modal-close'><%= Resources.labels.btnclose%></a>",
        //position: ["20%", ],
        overlayId: 'confirm-overlay',
        containerId: 'confirm-container',
        onShow: function (dialog) {
            var modal = this;
            $('.message', dialog.data[0]).append(message);
            // if the user clicks "yes"
            $('.yes', dialog.data[0]).click(function () {
                // call the callback
                if ($.isFunction(callback)) {
                    callback.apply();
                }
                // close the dialog
                //modal.close(); // or $.modal.close();
            });
        }
    });
}

function getCourseInfo(id){
    $.ajax({
        type: "get",
        cache: false,
        url: "Service/getCourse.aspx?id=" + id,
        success: function (msg) {
            $("#DivList").html(msg);
            $("#hidcid").val(id);
        },
        error: function (msg) {
            $("#DivList").html("<%= Resources.labels.GetInfoFail %>");
        }
    });
}
function editOK() {
    var cid = $("#hidcid").val();
    var cname = $("#cnameTxt").val();
    var knowlist = $("input[name='KnowTxt']");
    //$.modal.close();
    var ss = "";
    knowlist.each(function (i, n) {
        var o = $(n);
        ss += o.attr("knowid") + "$" + o.val()+"|";
    });
    //alert(cname + "\r\n" + ss); editcoursestatus
    $("#editcoursestatus").show();
    $.ajax({
        type: "post",
        cache: false,
        url: "Service/editCourse.aspx",
        data: "cid=" + cid + "&cname=" + cname + "&klist=" + ss,
        success: function (msg) {
            if (msg == "1") {
                $("#editcoursestatus").html("&nbsp;<img src='../images/ok.png' border=0 style='vertical-align:middle;' /><%= Resources.labels.Edit_OK%>").css("color", "#066606");
                window.setTimeout(refresh, 2000);
            } else {
                //alert("<%= Resources.labels.Del_Fail %>");
                $("#editcoursestatus").html("&nbsp;<img src='../images/erro.png' border=0 style='vertical-align:middle;' /><%= Resources.labels.Edit_Fail%>").css("color", "#FF0000");
            }
        },
        error: function (msg) {
            //alert("<%= Resources.labels.Del_Fail %>");
            $("#editcoursestatus").html("&nbsp;<img src='../images/erro.png' border=0 style='vertical-align:middle;' /><%= Resources.labels.Edit_Err%>").css("color", "#FF0000");
        }
    });
}
function editCancle(){

    $.modal.close();
}
function delKnow(kid) {
    var tr = $("#tr" + kid);
    tr.children().css("background-color", "#F0F0F0");
    //if (confirm("<%= Resources.labels.ConfirmDelete %>")) {
        $.ajax({
            type: "get",
            cache: false,
            url: "Service/delKnow.aspx?id=" + kid,
            success: function(msg) {
                if (msg == "1") {
                    $("#kstatus").html("&nbsp;<img src='../images/ok.png' border=0 style='vertical-align:middle;' /><%= Resources.labels.Del_ok%>").css("color", "#066606");
                    //window.setTimeout(tr.hide(), 2000);
                    tr.hide("slow");
                } else {
                    //alert("<%= Resources.labels.Del_Fail %>");
                    $("#kstatus").html("&nbsp;<img src='../images/erro.png' border=0 style='vertical-align:middle;' /><%= Resources.labels.Del_Fail%>").css("color", "#FF0000");
            
                }
            },
            error: function(msg) {
                //alert("<%= Resources.labels.Del_Fail %>");
                $("#kstatus").html("&nbsp;<img src='../images/erro.png' border=0 style='vertical-align:middle;' /><%= Resources.labels.Del_Fail%>").css("color", "#FF0000");
            }
        });
        
    //} else {
    //    tr.children().css("background-color", "#FFFFFF");
    //}
    return false;

}
</script>

</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server" EnableViewState="false">

<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td>
    <table id="dg" class="grid" border="0" cellspacing="0" cellpadding="0" width="100%">
        <thead>
            <tr>
                <th><%= Resources.labels.CourseList%></th>
            </tr>
        </thead>
        <tbody>
        <%foreach(Exam.Core.Model.Course obj in list){ %>
            <tr id="couTr<%=obj.Id.Trim() %>">
                <td>
                <div><a href="Course.aspx?id=<%=obj.Id.Trim() %>"><%=obj.Title %></a></div><br /> 
                    <div style="width:70%;HEIGHT:24PX;float:left;font-size:0.9em; color:#A3A3A3;margin-left:20px;">
                    <%=obj.KnowCount%><%= Resources.labels.Knowlidge%> 
                    <%= obj.QuestionCount.Trim()%><%= Resources.labels.Question%>
                    </div>
                    <div style="width:20%;HEIGHT:24PX;float:left;font-size:0.9em; color:#333;margin-left:20px;font-size:14px;">
                    <a href="javascript:void(0)" onclick='editCourse("<%=obj.Id.Trim() %>");return false;' class="uiButton"><%= Resources.labels.Edit%></a> 
                    <a href="javascript:void(0)" onclick='delCourse("<%=obj.Id.Trim() %>");return false;' class="uiButton"><%= Resources.labels.Delete%></a> 
                    </div>
                </td>
            </tr>
        <%} %>

        </tbody>
    	<tfoot>
    	    <tr>
    	        <td align=left>
    	<webdiyer:aspnetpager id="AspNetPager1" runat="server" 
    	    EnableViewState=false
    	    horizontalalign="Center" 
    	    PagingButtonSpacing="8px" 
            showcustominfosection="Left" 
            urlpaging="True" width="100%" 
            ImagePath="~/images" 
            NumericButtonType="Text" 
            ButtonImageExtension="gif" 
            ButtonImageNameExtension="n" 
            DisabledButtonImageNameExtension="g" 
            ShowNavigationToolTip="true" FirstPageText="<<" 
                        LastPageText=">>" NextPageText=">" PageSize="5" 
                        PrevPageText="<" SubmitButtonText="Go"></webdiyer:aspnetpager>
    	        </td>
    	    </tr>
    	</tfoot>
    </table>
</td>
<td class="rightsp"></td>
</tr>
</table>

<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td>
    <table class="grid" border="0" cellspacing="0" cellpadding="0" width="100%">
        <thead>
            <tr>
                <th><%= Resources.labels.count%></th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>
                    <asp:Label ID="Labtj" runat="server" Text="<%= Resources.labels.nocourse%>"></asp:Label></td>
            </tr>
        </tbody>
    </table>
</td>
<td class="rightsp"></td>
</tr>
</table>
<br />
<div class="btncontainer"><a href='#' id='BtnAdd' class="button"><%= Resources.labels.Add_Course%></a></div>

<!-- modal content -->
<div id="Add-modal-content">
	<div id="osx-modal-data">
		<p class="pmain">
        <%= Resources.labels.name%><br />
        <input id="coursename" name="coursename" type="text" style="width:375px;" />
        </p>
        <p class="pmain">
        <%= Resources.labels.descript%><br />
        <textarea id="coursedesc" cols="20" style="width:375px;" ></textarea>
        </p>
		<p id="result" class="pmain"></p>
        <p class="pmain">
        <button class="simplemodal-add button" onclick="addNew()"><%= Resources.labels.add%></button>&nbsp;
		<button class="simplemodal-close  button"><%= Resources.labels.cancel%></button></p>
	</div>
</div>

<DIV id="DivEditContainer" style="DISPLAY: none;" >
    <DIV style="DISPLAY: block;padding:5px;" id=DIV4 >
    <div id="DivList"><span class="loadicon"><%= Resources.labels.PleaseWaiting%></span></div>
    <div style="text-align:center;">
    <span id="editcoursestatus" class="status" style="display:none;font-size:0.8em;padding-top:5px;">
     &nbsp;<img src="../images/loading16x16.gif" border=0 style="vertical-align:middle;" /><%= Resources.labels.PleaseWaiting%>
    </span>
    <input id="Button9" type="button" class="button" value="<%= Resources.labels.btnok%>" onclick="editOK()" />
    <input id="Button3" type="button" class="button" value="<%= Resources.labels.btnclose%>" onclick="editCancle()" />
    <input id="hidcid" type="hidden" value="" />
    </div>
    </DIV>
    
</DIV>

<div id='confirm'>
	<div class='header'><span>&nbsp;<img src="../images/attention.png" style="vertical-align:middle;" /> <%= Resources.labels.warning%></span></div>
	<div class='message'></div>
	<span id="statusDel" class="status" style="display:none;font-size:0.8em;padding-top:5px;">
     &nbsp;<img src="../images/loading16x16.gif" border=0 style="vertical-align:middle;" /><%= Resources.labels.PleaseWaiting%>
    </span>
	<div class='buttons'>
		<div class='no simplemodal-close'><%= Resources.labels.cancel%></div>
		<div class='yes'><%= Resources.labels.Delete%></div>
		
	</div>
</div>

</asp:Content>

